// 参与抽奖的人员列表
const participants = ["Alice", "Bob", "Charlie", "David", "Eve", "Alex"];

// 显示所有参与者名单
const usersEle = document.getElementById("users")
usersEle.textContent = "参与者名单：" + participants;

// 抽奖函数
function drawLottery() {
    // 禁用按钮,防止重复点击
    document.getElementById("lottery-container").querySelector("button").disabled = true;

    // 随机选择一个参与者的索引
    const winnerIndex = Math.floor(Math.random() * participants.length);
    // 获取获奖者的名字
    const winner = participants[winnerIndex];

    // 将获奖者的名字显示在页面上,并添加文字翻滚动画
    const lotteryResult = document.getElementById("lottery-result");
    lotteryResult.classList.add("flip-animation");
    lotteryResult.textContent = "获奖者是:";

    // 3秒后移除文字翻滚动画,显示获奖者名字,重新启用按钮
    setTimeout(() => {
        lotteryResult.classList.remove("flip-animation");
        lotteryResult.textContent = `获奖者是: ${winner}!`;
        document.getElementById("lottery-container").querySelector("button").disabled = false;
        // 调用ArkTS函数，将结果通知原生端
        ohos.callNative("winner", { name: winner },(result) => {
            console.log('Html页面接收到原生的数据：' , result);
        })
    }, 3000);
}